package com.ficus.road.maintain.core.model.common;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Map;
import java.util.Objects;

/**
 * 通用的错误格式。
 */
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2020-05-19T20:52:46.669+08:00[Asia/Shanghai]")
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ErrorDTO {
    @JsonProperty("code")
    private ErrorCodeDTO code;

    @JsonProperty("retryable")
    private Boolean retryable;

    @JsonProperty("message")
    private String message;

    @JsonProperty("innerError")
    private InnerError innerError;

    @JsonProperty("property")
    private Map<String,Object> property;

    public ErrorDTO code(ErrorCodeDTO code) {
        this.code = code;
        return this;
    }

    /**
     * Get code
     *
     * @return code
     */
    @NotNull

    @Valid

    public ErrorCodeDTO getCode() {
        return code;
    }

    public void setCode(ErrorCodeDTO code) {
        this.code = code;
    }

    public ErrorDTO retryable(Boolean retryable) {
        this.retryable = retryable;
        return this;
    }

    /**
     * 此错误是否可重试。
     *
     * @return retryable
     */
    @NotNull


    public Boolean getRetryable() {
        return retryable;
    }

    public void setRetryable(Boolean retryable) {
        this.retryable = retryable;
    }

    public ErrorDTO message(String message) {
        this.message = message;
        return this;
    }

    /**
     * 错误的一句话描述。
     *
     * @return message
     */
    @NotNull


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ErrorDTO error = (ErrorDTO) o;
        return Objects.equals(this.code, error.code) &&
                Objects.equals(this.retryable, error.retryable) &&
                Objects.equals(this.message, error.message);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, retryable, message);
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("class ErrorDTO {\n");

        sb.append("    code: ").append(toIndentedString(code)).append("\n");
        sb.append("    retryable: ").append(toIndentedString(retryable)).append("\n");
        sb.append("    message: ").append(toIndentedString(message)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    /**
     * Convert the given object to string with each line indented by 4 spaces
     * (except the first line).
     */
    private String toIndentedString(Object o) {
        if (o == null) {
            return "null";
        }
        return o.toString().replace("\n", "\n    ");
    }
}

